﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BRS.BidModule
{
    public partial class frmBidderDetail : Form
    {
        Entities brs = new Entities();
        static string Dir = ConfigurationManager.AppSettings["ip"];
        static string ServerUser = ConfigurationManager.AppSettings["user"];
        static string ServerPassword = ConfigurationManager.AppSettings["password"];
          string filepath = ConfigurationManager.AppSettings["filepath"];
        public frmBidderDetail(int data)
        {
            InitializeComponent();
            Binds(data);
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
        public void Binds(int  data)
        {
            
            BidderInfo bidderinfo = brs.BidderInfo.Find(data);
            int cc = brs.BBInfo.Where(p => p.BidderInfoId == bidderinfo.Id).Select(p => p.BidderId).First();
            var bidpro = brs.tb_Bidder.Find(cc);
            string time = bidderinfo.CreateDate.Value.ToString(
                           "yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
            if (!Directory.Exists(filepath + "/投标人信息"))
            {
                Directory.CreateDirectory(filepath + "/投标人信息");//本地创建目录
            }
            if (!Directory.Exists(filepath + "/投标人信息/" + bidpro.Company))
            {
                Directory.CreateDirectory(filepath + "/投标人信息/" + bidpro.Company);//本地创建目录
            }
            string[] list4 = { "法定代表人", "企业负责人", "企业技术负责人", "项目负责人" };
            foreach (var p in list4)
            {
                string path = filepath + "/投标人信息/" + bidpro.Company + "/" + p;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);//本地创建目录
                }

            }
             FtpWeb ftpweb = new FtpWeb(Dir, "投标人信息"+ "/"+bidpro.Company+ "/" + bidderinfo.BidderType , ServerUser, ServerPassword);
             string live = filepath +"/投标人信息/"+ bidpro.Company + "/" + bidderinfo.BidderType + "/现场" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg";
             string idp = filepath +"/投标人信息/"+ bidpro.Company + "/" + bidderinfo.BidderType + "/身份证" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg";
             string scan = filepath +"/投标人信息/"+ bidpro.Company + "/" + bidderinfo.BidderType + "/证明" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg";

             if (!File.Exists(live))   //判断文件是否存在
             {
                 ftpweb.Download(filepath + "/投标人信息/" + bidpro.Company + "/" + bidderinfo.BidderType, "现场" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg");
             }

             if (!File.Exists(idp))   //判断文件是否存在
             {
                 ftpweb.Download(filepath + "/投标人信息/" + bidpro.Company + "/" + bidderinfo.BidderType, "身份证" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg");
             }
             if (!File.Exists(scan))   //判断文件是否存在
             {
                 ftpweb.Download(filepath + "/投标人信息/" + bidpro.Company + "/" + bidderinfo.BidderType, "证明" + bidderinfo.BidderType + bidderinfo.Name + time + ".jpg");
             }
            LiftPicture.ImageLocation =live; // bidpro.FilePath + bidpro.Company + "/" + bidderinfo.BidderType + "/现场" + bidderinfo.BidderType  +bidderinfo.Name+ time+ ".jpg";
            IDPitcture.ImageLocation =idp;   //bidpro.FilePath + bidpro.Company + "/" + bidderinfo.BidderType + "/身份证" + bidderinfo.BidderType  + bidderinfo.Name+ time +".jpg";
            Scanpicture.ImageLocation =scan; // bidpro.FilePath + bidpro.Company + "/" + bidderinfo.BidderType + "/证明" + bidderinfo.BidderType  +bidderinfo.Name+ time + ".jpg";
            //MessageBox.Show(IDPitcture.ImageLocation.ToString());
            //label1.Text = LiftPicture.ImageLocation;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
